library OrderTypes
/*******************************
 * Order Types Library
 * ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
 * by: Berb
 * Version: 1.0
 * 
 * Description:
 * ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
 *	The purpose of this library is to provide the user with an API function that allows
 *	them to easily (and efficiently) check which type of order the current event response
 *	is dealing with. It uses event responses such as "GetOrderPointLoc" so using this 
 *	outside of an event response action will not work.
 *
 * API:
 * ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
 *      • GetOrderType                  ~ Returns an integer constant representing the type
 *                                      of order that is in-process. 
 *      • GetAbilityOrderType           ~ Just like "GetOrderType" except for ability
 *                                      events rather than order events.
 *
 *      • GetOrderTargetType            ~ Returns an integer constant representing the type
 *                                      of target that the order was issued on.
 *      • GetAbilityOrderTargetType     ~ Just like "GetOrderTargetType" except for ability
 *                                      events rather than order events.
 *
 * Constants -------------------------------------------------------------------------------*/
    globals

        public constant	integer     ORDER_TYPE_NONE     = 0
        public constant	integer     ORDER_TYPE_POINT    = 1
        public constant	integer     ORDER_TYPE_TARGET   = 2
        
        public constant    integer     TARGET_TYPE_UNIT    = 0
        public constant    integer     TARGET_TYPE_DEST    = 1
        public constant    integer     TARGET_TYPE_ITEM    = 2
        public constant    integer     TARGET_TYPE_NONE    = 3
        
    endglobals
/* -----------------------------------------------------------------------------------------
 * 
 */
    globals
        private     location	data__targetLoc		= null
    endglobals
				
    function GetAbilityOrderTargetType takes nothing returns integer
        if GetSpellTargetUnit() != null then
            return TARGET_TYPE_UNIT
        elseif GetSpellTargetItem() != null then
            return TARGET_TYPE_ITEM
        elseif GetSpellTargetDestructable() != null then
            return TARGET_TYPE_DEST
        endif
        return TARGET_TYPE_NONE
    endfunction
                
    function GetAbilityOrderType takes nothing returns integer   
        if GetSpellTargetUnit() != null     or /*
            */ GetSpellTargetItem() != null or /*
            */ GetSpellTargetDestructable() != null then
            return ORDER_TYPE_TARGET
        endif
        
        set data__targetLoc = GetSpellTargetLoc()    
        if data__targetLoc != null then
            call RemoveLocation(data__targetLoc)
            return ORDER_TYPE_POINT
        endif
        return ORDER_TYPE_NONE
    endfunction
        
    function GetOrderTargetType takes nothing returns integer
        if GetOrderTargetUnit() != null then
            return TARGET_TYPE_UNIT
        elseif GetOrderTargetItem() != null then
            return TARGET_TYPE_ITEM
        elseif GetOrderTargetDestructable() != null then
            return TARGET_TYPE_DEST
        endif
        return TARGET_TYPE_NONE
    endfunction
        
    function GetOrderType takes nothing returns integer
        if GetOrderTarget() != null then
            return ORDER_TYPE_TARGET
        endif
        
        set data__targetLoc = GetOrderPointLoc()
        if data__targetLoc != null then
            call RemoveLocation(data__targetLoc)
            return ORDER_TYPE_POINT
        endif
        return ORDER_TYPE_NONE
    endfunction

 endlibrary